package com.qf.mapper;

import com.qf.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserMapper {
    //登录
    @Select("select * from tb_user where username=#{username} and password=#{password}")
    public User login(User user);
    //查询
    @Select("select * from tb_user")
    List<User> findAll();
    @Select("select * from tb_user where username=#{username}")
    User findByUsername(String username);
    // 添加注册方法
    @Insert("insert into tb_user(username, password, phone, create_time, money, sex) " +
            "values(#{username}, #{password}, #{phone}, #{createTime}, #{money}, #{sex})")
    void register(User user);
    //单行删除
    @Delete("delete from tb_user where id=#{id} ")
    void delete(Integer id);
    //批量删除
    @Delete("<script>" +
            "delete from tb_user where id in " +
            "<foreach collection='ids' item='id' open='(' separator=',' close=')'>" +
            " #{id} " +
            "</foreach>" +
            "</script>")
    void batchDeleteUser(@Param("ids") List<Integer> ids);
    //模糊查询
    @Select("select * from tb_user where username like concat('%', #{username}, '%')")
    List<User> findByUsernameLike(String username);
}
